<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="search_from">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">用户id</label>
                            <div class="layui-input-inline">
                                <input type="text" name="m_id" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">用户名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="username" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="search_button">
                                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                            </button>
                        </div>
                    </div>
                </div>

                <script type="text/html" id="toolbar_tmp">
                    <div class="layui-btn-container">
                        <button class="layui-btn layui-btn-sm" lay-event="add">批量充值</button>
                    </div>
                </script>

                <div class="layui-card-body">
                    <table id="table_list" lay-filter="table_list"></table>
                    <script type="text/html" id="action_button">
                        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">明细</a>
                        <a class="layui-btn layui-btn-xs" lay-event="recharge">充值</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="deduct">扣除</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="../../../layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'helper'], function () {
        var admin = layui.admin,
            table = layui.table,
            form = layui.form,
            helper = layui.helper,
            api_action_url = layui.setter.apiHost + '/financial/balance';

        //表格操作
        table.render({
            elem: '#table_list',
            url: api_action_url,
            toolbar: '#toolbar_tmp',
            cols: [[
                {field: 'id', title: 'ID', width: 80},
                {field: 'username', title: '用户名', minWidth: 170},
                {field: 'amount', title: '账户金额'},
                {field: 'updated_at', title: '最后变更时间', width: 170},
                {title: '操作', width: 170, align: 'center', fixed: 'right', toolbar: '#action_button'}
            ]],
            page: true
        });

        //头部工具栏操作
        table.on('toolbar(table_list)', function (obj) {
            var type = obj.event;
            switch (type) {
                case 'add':
                    var set_data = {
                        save_url: api_action_url + '/batch_recharge',//保存地址
                    };
                    helper.open_window('批量充值', api_action_url, 'financial/balance/add', set_data);
                    break;
                case 'status_on':
                    helper.ajax(api_action_url + '/status', {status: 1});
                    break;
                case 'status_off':
                    helper.ajax(api_action_url + '/status', {status: 0});
                    break;
                case 'del':
                    layer.confirm('确定删除吗', function (index) {
                        helper.ajax(api_action_url + '/delete');
                    });
                    break;
            }
        });

        //监听工具条操作按钮
        table.on('tool(table_list)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'detail':
                    helper.open_iframe('明细', 'detail.html?id=' + data.m_id);
                    break;
                case 'recharge':
                    var set_data = {
                        save_url: api_action_url + '/recharge',//保存地址
                    };
                    helper.open_window('充值', api_action_url, 'financial/balance/recharge', set_data, {m_id: data.m_id});
                    break;
                case 'deduct':
                    var set_data = {
                        save_url: api_action_url + '/deduct',//保存地址
                    };
                    helper.open_window('扣除', api_action_url, 'financial/balance/deduct', set_data, {m_id: data.m_id});
                    break;
            }
        });
    });
</script>
</body>
</html>